package com.atguigu.jinx.enums;

/**
 * @author steve
 * @date 2025/08/27 18:34
 */
import lombok.AllArgsConstructor;
import lombok.Getter;

@Getter
@AllArgsConstructor
public enum PayMethodStatus {
    ALIPAY((byte)1, "支付宝"),
    WECHAT((byte)2, "微信");

    private final byte code;
    private final String name;

    /**
     * 根据 code 获取枚举
     */
    public static PayMethodStatus fromCode(byte code) {
        for (PayMethodStatus status : PayMethodStatus.values()) {
            if (status.getCode() == code) {
                return status;
            }
        }
        throw new IllegalArgumentException("Unknown code: " + code);
    }

    /**
     * 根据 code 获取 name
     */
    public static String getNameByCode(byte code) {
        for (PayMethodStatus status : PayMethodStatus.values()) {
            if (status.getCode() == code) {
                return status.getName();
            }
        }
        return null;
    }
}
